package com.ayoka.parenting.ui.group.manager;

import com.ayoka.parenting.R;
import com.ayoka.parenting.bean.BaseResponse;
import com.ayoka.parenting.bean.CircleMemberBean;
import com.ayoka.parenting.bean.PagerBean;
import com.ayoka.parenting.interf.SimpleRequestCallback;
import com.ayoka.parenting.mvp.BasePresenterImpl;
import com.jincp.common.utils.UIUtils;

/**
 * @ProjectName: MVPPlugin.
 * @ClassName: MemberManagerPresenter.
 * @Description: .
 * @Author: jincp.
 * @CreateDate: 2019/10/10 18:17.
 */
public class MemberManagerPresenter extends BasePresenterImpl<MemberManagerContract.View> implements MemberManagerContract.Presenter {

    private MemberManagerModel model;

    public MemberManagerPresenter() {
        model = new MemberManagerModel();
    }

    @Override
    public void getCircleGroupMemberListData(boolean isShowWaitDialog, String topicId, int pageNo, int pageSize) {
        if (isShowWaitDialog) {
            mView.get().showWaitDialog(UIUtils.getString(R.string.loading));
        }
        model.getCircleGroupMemberListData(this, topicId, pageNo, pageSize, new SimpleRequestCallback<PagerBean<CircleMemberBean>>() {
            @Override
            public void onSuccess(PagerBean<CircleMemberBean> response) {
                if (!isAttached()) return;
                mView.get().hideWaitDialog();
                mView.get().configCircleGroupMemberListData(response);
            }

            @Override
            public void onFailure(int errorCode, String errorMessage) {
                if (!isAttached()) return;
                mView.get().hideWaitDialog();
                mView.get().showToast(errorMessage);
            }
        });
    }

    @Override
    public void agreeApply(String topicId, String userId, final int position) {
        mView.get().showWaitDialog(UIUtils.getString(R.string.loading));
        model.agreeApply(this, topicId, userId, new SimpleRequestCallback<BaseResponse>() {
            @Override
            public void onSuccess(BaseResponse response) {
                if (!isAttached()) return;
                mView.get().hideWaitDialog();
                mView.get().onAgreeApplyCallback(true, position);
            }

            @Override
            public void onFailure(int errorCode, String errorMessage) {
                if (!isAttached()) return;
                mView.get().hideWaitDialog();
                mView.get().showToast(errorMessage);
                mView.get().onAgreeApplyCallback(false, position);
            }
        });
    }

    @Override
    public void deleteMember(String topicId, String userId, final int position) {
        mView.get().showWaitDialog(UIUtils.getString(R.string.loading));
        model.deleteMember(this, topicId, userId, new SimpleRequestCallback<BaseResponse>() {
            @Override
            public void onSuccess(BaseResponse response) {
                if (!isAttached()) return;
                mView.get().hideWaitDialog();
                mView.get().onDeleteMemberCallback(true, position);
            }

            @Override
            public void onFailure(int errorCode, String errorMessage) {
                if (!isAttached()) return;
                mView.get().hideWaitDialog();
                mView.get().showToast(errorMessage);
                mView.get().onDeleteMemberCallback(false, position);
            }
        });
    }
}
